package com.hcr.action;


import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.hcr.model.Department;
import com.hcr.service.DepartmentService;
import com.hcr.service.UserService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
@Component("departmentAction")
public class DepartmentAction extends ActionSupport implements ModelDriven<Department>{
	/**
	 * 
	 */
	private static final long serialVersionUID = 2875900921021771659L;
	private Department department=new Department();
	private DepartmentService departmentService;
	private UserService userService;
	public UserService getUserService() {
		return userService;
	}
	@Resource(name="userService")
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	public DepartmentService getDepartmentService() {
		return departmentService;
	}
	@Resource(name="departmentService")
	public void setDepartmentService(DepartmentService departmentService) {
		this.departmentService = departmentService;
	}

	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}
	public String addDepartment(){
		return "add";
	}
	public String add(){
		this.departmentService.add(department);
		return "showdepartment";
	}
	public String showDepartment(){
		List<Department> departments=this.departmentService.findAll();
		ActionContext context=ActionContext.getContext();
		context.put("departments",departments);
		return "success";
	}

	public String delete(){
		this.userService.updateDepartment(department);
		this.departmentService.delete(department);
		System.out.println("*********"+department.getName());
		return "showdepartment";
	}
	public String updateDepartment(){
		return "update";
	}
	public String update(){
		this.departmentService.update(department);
		return "showdepartment";
	}

	public Department getModel() {
		return this.department;
	}
}
